package com.project.controller;

import com.project.bean.BuyCarBean;
import com.project.bean.UserBean;
import com.project.service.IBuyCarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.List;

/**
 * 采购车controller
 */
@RequestMapping("buyCar")
@RestController
public class BuyCarController {

    @Autowired
    private IBuyCarService buyCarService;

    //根据登录用户id查询该采购员的所有采购车
    @RequestMapping("findByUserId")
    public List<BuyCarBean> findByUserId(HttpServletRequest request){
        UserBean loginUser = (UserBean) request.getSession().getAttribute("loginUser");
        return buyCarService.findByUserId(loginUser.getId());
    }

    //按照采购车id删除采购车
    @RequestMapping("del")
    public String del(Integer buyCarId){
        buyCarService.del(buyCarId);
        return "ok";
    }

    //按照采购车id修改采购价和采购数量
    @RequestMapping("update")
    public String update(Integer id,Integer price,Integer num){
        buyCarService.update(id, price, num);
        return "ok";
    }


}
